package com.qh.yyxt.service.Impl;

import com.qh.yyxt.entity.Borrow;
import com.qh.yyxt.pojo.entity.meeting.DelayBorrow;
import com.qh.yyxt.mapper.BorrowMapper;
import com.qh.yyxt.mapper.DelayBorrowMapper;
import com.qh.yyxt.mapper.MeetingMapper;
import com.qh.yyxt.pojo.BorrowPartDTO;
import com.qh.yyxt.service.DelayBorrowService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DelayBorrowServiceImpl implements DelayBorrowService
{

    @Autowired
    private DelayBorrowMapper delayBorrowMapper;
    @Autowired
    private BorrowMapper borrowMapper;
    @Autowired
    private MeetingMapper meetingMapper;
    @Override
    public int add(DelayBorrow delayBorrow) {
            int result=-1;
        try {
            result=delayBorrowMapper.add(delayBorrow);
        } catch (Exception e) {
           // e.printStackTrace();
            result=-1;
        }
        return result;
    }

    @Override
    public int update(int bid, String state)
    {
        //System.out.println(bid+"   "+state);
        return delayBorrowMapper.update(bid,state);
    }

    @Override
    public DelayBorrow getByBid(int bid) {
        return delayBorrowMapper.getByBid(bid);
    }

    @Override
    public DelayBorrow findById(int id) {
        return delayBorrowMapper.findById(id);
    }

    @Override
    public List<BorrowPartDTO> getDelay() {
       List<DelayBorrow>list=delayBorrowMapper.findAll();
       List<BorrowPartDTO>dtoList=new ArrayList<>();
        for (DelayBorrow delayBorrow:list)
        {
            BorrowPartDTO borrowPartDTO=new BorrowPartDTO();
            Borrow b=borrowMapper.findById(delayBorrow.getBid());
              borrowPartDTO.set(b);
              if(b!=null)
            borrowPartDTO.setMidName(meetingMapper.findById(b.getMid()));
            borrowPartDTO.setDelaystate(delayBorrow.getDelaystate());
            borrowPartDTO.setDelaytime(delayBorrow.getDelaytime());
            dtoList.add(borrowPartDTO);
        }
        return dtoList;
    }
}
